#!/usr/bin/env python
# -*- coding: UTF-8 -*-

class MemoryStorage:
    def __init__(self):
        self.__packets = {}

    def add(self, packet):
        self.__packets[packet.name] = packet
        return packet
    
    def add_range(self, packets):
        [self.add(packet) for packet in packets]

    @property
    def entries(self):
        return self.__packets.values()

    def remove(self, packet_name):
        if packet_name in self.__packets:
            del self.__packets[packet_name]

    def update(self, packet):
        self.remove(packet.name)
        self.add(packet)